/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 * aion-unique is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-unique is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.questEngine.model;

import com.aionengine.gameserver.model.DialogAction;
import com.aionengine.gameserver.model.gameobjects.Gatherable;
import com.aionengine.gameserver.model.gameobjects.Npc;
import com.aionengine.gameserver.model.gameobjects.StaticObject;
import com.aionengine.gameserver.model.gameobjects.VisibleObject;
import com.aionengine.gameserver.model.gameobjects.player.Player;
import com.aionengine.gameserver.questEngine.QuestEngine;

/**
 * @author MrPoke
 */
public class QuestEnv {

    private VisibleObject visibleObject;
    private Player player;
    private int questId;
    private int dialogId;
    private int extendedRewardIndex;

    /**
     * @param creature
     * @param player
     * @param questId
     */
    public QuestEnv(VisibleObject visibleObject, Player player, Integer questId, Integer dialogId) {
        super();
        this.visibleObject = visibleObject;
        this.player = player;
        this.questId = questId;
        this.dialogId = dialogId;
    }

    /**
     * @return the visibleObject
     */
    public VisibleObject getVisibleObject() {
        return visibleObject;
    }

    /**
     * @param visibleObject the visibleObject to set
     */
    public void setVisibleObject(VisibleObject visibleObject) {
        this.visibleObject = visibleObject;
    }

    /**
     * @return the player
     */
    public Player getPlayer() {
        return player;
    }

    /**
     * @param player the player to set
     */
    public void setPlayer(Player player) {
        this.player = player;
    }

    /**
     * @return the questId
     */
    public Integer getQuestId() {
        return questId;
    }

    /**
     * @param questId the questId to set
     */
    public void setQuestId(Integer questId) {
        this.questId = questId;
    }

    /**
     * @return the dialogId
     */
    public Integer getDialogId() {
        return dialogId;
    }

    public DialogAction getDialog() {
        DialogAction dialog = QuestEngine.getInstance().getDialog(dialogId);
        if (dialog == null) {
            return DialogAction.NULL;
        }
        return dialog;
    }

    /**
     * @param dialogId the dialogId to set
     */
    public void setDialogId(Integer dialogId) {
        this.dialogId = dialogId;
    }

    public int getTargetId() {
        if (visibleObject == null) {
            return 0;
        } else if (visibleObject instanceof Npc) {
            return ((Npc) visibleObject).getNpcId();
        } else if (visibleObject instanceof Gatherable) {
            return ((Gatherable) visibleObject).getObjectTemplate().getTemplateId();
        } else if (visibleObject instanceof StaticObject) {
            return ((StaticObject) visibleObject).getObjectTemplate().getTemplateId();
        }
        return 0;
    }

    public void setExtendedRewardIndex(int index) {
        this.extendedRewardIndex = index;
    }

    public int getExtendedRewardIndex() {
        return this.extendedRewardIndex;
    }
}
